import { defineConfig, loadEnv } from 'vite'
import usePluginImport from 'vite-plugin-importer'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd())
  return {
    // base: env.VITE_BASE_URL || '/',
    resolve: {
      alias: {
        '@': '/src',
        assets: '/src/assets',
        components: '/src/components',
        share: '/src/share',
        store: '/src/store',
      },
    },
    css: {
      modules: {
        scopeBehaviour: 'local',
        localsConvention: 'camelCaseOnly',
      },
      preprocessorOptions: {
        less: {
          javascriptEnabled: true,
          additionalData: '@import "src/style/preset.less";',
        },
      },
      postcss: 'postcss.config.js',
    },
    plugins: [
      react(),
      // eslint-disable-next-line react-hooks/rules-of-hooks
      usePluginImport({
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: true,
      }),
    ],
    server: {
      proxy: {
        '^/api': {
          ws: false,
          target: env.VITE_API_PROXY_HOST,
          changeOrigin: true,
        },
      },
    },
    optimizeDeps: {
      include: ['react/jsx-runtime'],
    },
  }
})
